J.A.D.E.: The Java Addition to the Default Environment
by Jean-Marie Dautelle
Listing One
package com.dautelle.geom2d;
public class Point {
double x;
double y;
// XML constructor.
public Point(Attributes attributes, Elements content) {
x = attributes.getDouble("x");
y = attributes.getDouble("y");
}
}
public abstract class Surface {}
public class Ellipse extends Surface {
Point center;
double width;
double height;
// XML constructor.
public Ellipse(Attributes attributes, Elements content) {
center = (Point) content.get(0);
width = attributes.getDouble("width");
height = attributes.getDouble("height");
}
}
public class Polygon extends Surface {
Point [] vertices;
// XML constructor.
public Polygon(Attributes attributes, Elements content) {
vertices = new Point[content.size()];
content.toArray(vertices);
}
}
public class Area extends Surface {
Surface [] surfaces;
// XML constructor.
public Area(Attributes attributes, Elements content) {
surfaces = new Surface[content.size()];
content.toArray(surfaces);
}
}
Listing Two
Listing Three
Listing Four
package com.dautelle.geom2d;
import com.dautelle.xml.*;
public class Point extends Representable {
double x;
double y;
public Attributes getAttributes() {
Attributes attributes = new Attributes();
attributes.add("x", x);
attributes.add("y", y);
return attributes;
}
public Representable[] getContent() {
return null;
}
}
public abstract class Surface extends Representable {}
public class Ellipse extends Surface {
Point center;
double width;
double height;
public Attributes getAttributes() {
Attributes attributes = new Attributes();
attributes.add("width", width);
attributes.add("height", height);
return attributes;
}
public Representable[] getContent() {
return new Representable[] { center };
}
}
public class Polygon extends Surface {
Point [] vertices;
public Attributes getAttributes() {
return null;
}
public Representable[] getContent() {
return vertices;
}
}
public class Area extends Surface {
Surface [] surfaces;
public Attributes getAttributes() {
return null;
}
public Representable[] getContent() {
return surfaces;
}
}
3